package org.ucas.faker.web.fetcher.cond;

import org.ucas.faker.web.fetcher.meta.ColumnField;
import org.ucas.faker.web.fetcher.meta.Table;

import java.io.Serializable;

public class RangeCond extends FetchCond implements Serializable {

  public ColumnField column;

  public ColumnField upper;

  public ColumnField lower;


  @Override
  public String sql() {
    if(column == null || (upper == null && lower == null)) return "";

    String res = "";
    if(upper != null) res += column.sql() + " <= " + upper.sql();

    if(lower != null) res += (upper == null? "": " AND ") + column.sql() + " >= " + lower.sql();

    return res;
  }

  @Override
  public void replace(Table src, Table dst) {
    if(column != null) column.replace(src,dst);
  }
}
